﻿using System;
using System.Runtime.Serialization;
using ManoMachine.Assembler.Parsers;

namespace ManoMachine.Assembler.Exceptions
{
    public class AssemblerException : Exception
    {
        public AssemblerException(string message, AssemblyLine line) : base(message)
        {
            Line = line;
            if (Line != null) Line.Error = this;
        }

        public AssemblerException(string message, Exception innerException, AssemblyLine line) : base(message, innerException)
        {
            Line = line;
            if (Line != null) Line.Error = this;
        }

        protected AssemblerException(SerializationInfo info, StreamingContext context, AssemblyLine line) : base(info, context)
        {
            Line = line;
            if (Line != null) Line.Error = this;
        }

        public AssemblyLine Line { get; private set; }

        public override string ToString()
        {
            return string.Format("{1:D02}\n{0}", this.Message, Line);
        }
    }
}